<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/17 0017
  Time: 上午 10:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>投票管理-添加</title>

    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/static/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">

    <link rel="stylesheet" href="/static/css/common.css">

</head>
<body>
<div class="wrap-padding-15">
    <span class="layui-breadcrumb">
          <a href="/" target="_top">首页</a>
          <a href="/vote">投票管理</a>
          <a><cite>增加</cite></a>
     </span>

    <div class="box-form">
        <form action="/vote/save" method="post" class="layui-form">

            <div class="layui-form-item">
                <label class="layui-form-label">标题：</label>
                <div class="layui-input-block">
                    <input type="text" name="title"  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Banner：</label>
                <div class="layui-input-block">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test1">上传图片</button>
                        <input type="hidden" name="banner" id="banner">
                        <div class="layui-upload-list">
                            <img style="width: 100px; height: 100px" class="layui-upload-img" id="demo1">
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">起止时间：</label>
                <div class="layui-input-block">
                    <div class="site-demo-laydate">
                        <input type="text" name="qzTime"  id="time" placeholder="-"  class="layui-input">

                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态：</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="status" value="1" title="发布">
                </div>
            </div>



            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSubmit">提交</button>
                    <a href="/vote"><button type="button" class="layui-btn layui-btn-primary">取消</button></a>
                </div>
            </div>

        </form>
    </div>

</div>




<script src="/static/plugins/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/static/plugins/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/static/plugins/ztree/js/jquery.ztree.excheck.js"></script>


<script>

    layui.use(['element','layer','form','upload','laydate'], function(){
        var form = layui.form;
        var upload = layui.upload;
        var laydate = layui.laydate;
         var layer = layui.layer;
        laydate.render({
            elem: '#time'
            ,type: 'datetime'
            ,range:'~'
        });


        //监听提交
        form.on('submit(formSubmit)',function (data) {
            $.ajax({
                url:"/vote/save",
                type:"post",
                dataType:"json",
                data:data.field,
                success:function (rs) {
                    layer.msg(rs.message,{time:1000,icon:1},function () {
                        if(rs.code==1){
                            location.href = "/vote/edit?id="+rs.data+"&tabId=2";
                        }
                    })
                },
                error:function () {
                    layer.msg("服务器繁忙，请稍后再试")
                }
            })
            return false
        })


        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/upload'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
              /*  if(res.code > 0){
                    return layer.msg('上传失败');
                }*/
                $("#banner").val(res[0].src);

                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


    });


</script>
</body>
</html>
